clear all
set mem 400m
set matsize 150


**********************************************************************************************************************
********************** I. Data Base ****************************************************************************
**********************************************************************************************************************

* I.a We open the data base:

cd /Users/louisianateixeira/Desktop/StataPaper

use ./data/data_paper.dta, clear


**********************************Transformations********************************************************************* 
******************************* I.b LOG ******************************************************************************


****************** Defining y

*Labor outputs
gen log_NonTravail_enfants =log(NonTravail_enfants + 2) if NonTravail_enfants!=.
gen log_Egalite_Salaire_genre =log(Egalite_Salaire_genre + 2) if Egalite_Salaire_genre!=.
gen log_Egalite_NonBlanc_Blanc =log(Egalite_NonBlanc_Blanc + 2) if Egalite_NonBlanc_Blanc!=.


*Social outputs
gen log_TaxaAlfabetismo =log(TaxaAlfabetismo + 2) if TaxaAlfabetismo!=.
gen log_CriançaRespAlfabet =log(CriançaRespAlfabet + 2) if CriançaRespAlfabet!=.
gen log_CriançaSaneamAdeq =log(CriançaSaneamAdeq + 2) if CriançaSaneamAdeq!=.
gen log_CriançaRespAlfabSaneamAdeq =log(CriançaRespAlfabSaneamAdeq + 2) if CriançaRespAlfabSaneamAdeq!=.
gen log_IncidenceDeNon_Pauvrété =log(IncidenceDeNon_Pauvrété + 2) if IncidenceDeNon_Pauvrété!=.
gen log_NonGINI =log(NonGINI + 2) if NonGINI!=.


****************** Defining x
gen log_Distance_capitale =log(Distance_capitale + 2) if Distance_capitale!=.
gen log_Densite_demographique =log(Densite_demographique + 2) if Densite_demographique!=.
gen log_PIB_tete =log(PIB_tete + 2) if PIB_tete!=.
gen log_Pop_urbaine =log(Pop_urbaine + 2) if Pop_urbaine!=.


******************************* I.c Square root Municipality population  ******************************************************************************

gen sqrt_Mun_pop = sqrt(Municipality_pop)


************************************************************************************************************************
*************************   II. REGRESSIONS   **********************************************************************
************************************************************************************************************************

****************** Model A - Residuals

*Labor outputs
reg log_NonTravail_enfants log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], vce(robust)
estimates store model1
reg log_Egalite_Salaire_genre log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], vce(robust) 
estimates store model2
reg log_Egalite_NonBlanc_Blanc log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], vce(robust)
estimates store model3

esttab model1 model2 model3 using "./results/laborregressionsA_sqw.xls", b(3) se(2) ar2(4) 


*Social outputs
reg log_TaxaAlfabetismo log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], vce(robust)
estimates store model1
reg log_CriançaRespAlfabet log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], vce(robust)
estimates store model2
reg log_CriançaSaneamAdeq log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], vce(robust)
estimates store model3
reg log_CriançaRespAlfabSaneamAdeq log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], vce(robust)
estimates store model4
reg log_IncidenceDeNon_Pauvrété log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], vce(robust)
estimates store model5
reg log_NonGINI log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], vce(robust)
estimates store model6

esttab model1 model2 model3 model4 model5 model6 using "./results/socialregressionsA_sqw.xls", b(3) se(2) ar2(4) 



****************** Model B - Stochastic Frontier

*Labor outputs
sfcross log_NonTravail_enfants log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], model(bc) dist(tn) ort(o) vce(robust)
estimates store model1
sfcross log_Egalite_Salaire_genre log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], model(bc) dist(tn) ort(o) vce(robust)
estimates store model2
sfcross log_Egalite_NonBlanc_Blanc log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], model(bc) dist(tn) ort(o) vce(robust)
estimates store model3

esttab model1 model2 model3 using "./results/laborregressionsB_sqw.xls", b(3) se(2) scalar("sigma_u Sigma_u" "sigma_v Sigma_v" "lambda Lambda")


*Social outputs
sfcross log_TaxaAlfabetismo log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], model(bc) dist(tn) ort(o) vce(robust)
estimates store model1
sfcross log_CriançaRespAlfabet log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], model(bc) dist(tn) ort(o) vce(robust)
estimates store model2
sfcross log_CriançaSaneamAdeq log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], model(bc) dist(tn) ort(o) vce(robust)
estimates store model3
sfcross log_CriançaRespAlfabSaneamAdeq log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], model(bc) dist(tn) ort(o) vce(robust)
estimates store model4
sfcross log_IncidenceDeNon_Pauvrété log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], model(bc) dist(tn) ort(o) vce(robust)
estimates store model5
sfcross log_NonGINI log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], model(bc) dist(tn) ort(o) vce(robust)
estimates store model6

esttab model1 model2 model3 model4 model5 model6 using "./results/socialregressionsB_sqw.xls", b(3) se(2) scalar("sigma_u Sigma_u" "sigma_v Sigma_v" "lambda Lambda")



************************************************************************************************************************
*************************   III. RESIDUALS AND TECHNICAL INEFFICIENCY  **********************************************************************
************************************************************************************************************************

****************** Model A - Residuals

*Labor outputs
reg log_NonTravail_enfants log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], vce(robust)
predict r_NonTravail_enfants, r
reg log_Egalite_Salaire_genre log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], vce(robust)
predict r_Egalite_Salaire_genre, r
reg log_Egalite_NonBlanc_Blanc log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], vce(robust)
predict r_Egalite_NonBlanc_Blanc, r


*Social outputs
reg log_TaxaAlfabetismo log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], vce(robust)
predict r_TaxaAlfabetismo, r
reg log_CriançaRespAlfabet log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], vce(robust)
predict r_CriançaRespAlfabet, r
reg log_CriançaSaneamAdeq log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], vce(robust)
predict r_CriançaSaneamAdeq, r
reg log_CriançaRespAlfabSaneamAdeq log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], vce(robust)
predict r_CriançaRespAlfabSaneamAdeq, r
reg log_IncidenceDeNon_Pauvrété log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], vce(robust)
predict r_IncidenceDeNon_Pauvrété, r
reg log_NonGINI log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], vce(robust)
predict r_NonGINI, r


****************** Model B - Stochastic Frontier

*Labor outputs
sfcross log_NonTravail_enfants log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], model(bc) dist(tn) ort(o) vce(robust)
predict u_NonTravail_enfants, u
sfcross log_Egalite_Salaire_genre log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], model(bc) dist(tn) ort(o) vce(robust)
predict u_Egalite_Salaire_genre, u
sfcross log_Egalite_NonBlanc_Blanc log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], model(bc) dist(tn) ort(o) vce(robust)
predict u_Egalite_NonBlanc_Blanc, u

*Social outputs
sfcross log_TaxaAlfabetismo log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], model(bc) dist(tn) ort(o) vce(robust) 
predict u_TaxaAlfabetismo, u
sfcross log_CriançaRespAlfabet log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], model(bc) dist(tn) ort(o) vce(robust)
predict u_CriançaRespAlfabet, u
sfcross log_CriançaSaneamAdeq log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], model(bc) dist(tn) ort(o) vce(robust)
predict u_CriançaSaneamAdeq, u
sfcross log_CriançaRespAlfabSaneamAdeq log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], model(bc) dist(tn) ort(o) vce(robust)
predict u_CriançaRespAlfabSaneamAdeq, u
sfcross log_IncidenceDeNon_Pauvrété log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], model(bc) dist(tn) ort(o) vce(robust)
predict u_IncidenceDeNon_Pauvrété, u
sfcross log_NonGINI log_PIB_tete log_Distance_capitale log_Densite_demographique log_Pop_urbaine Dummy_Capital AC AP PA RO RR TO AL BA CE MA PB PE PI RN SE DF GO MS MT ES MG RJ SP PR RS SC [aweight=sqrt_Mun_pop], model(bc) dist(tn) ort(o) vce(robust)
predict u_NonGINI, u


************************************************************************************************************************
*************************   IV. CORRELATION INEFFICIENCY-RESIDUALS **********************************************************************
************************************************************************************************************************

*Graphs:

scatter u_NonTravail_enfants r_NonTravail_enfants
scatter u_Egalite_Salaire_genre r_Egalite_Salaire_genre
scatter u_Egalite_NonBlanc_Blanc r_Egalite_NonBlanc_Blanc
scatter u_TaxaAlfabetismo r_TaxaAlfabetismo
scatter u_CriançaRespAlfabet r_CriançaRespAlfabet
scatter u_CriançaSaneamAdeq r_CriançaSaneamAdeq
scatter u_CriançaRespAlfabSaneamAdeq r_CriançaRespAlfabSaneamAdeq
scatter u_IncidenceDeNon_Pauvrété r_IncidenceDeNon_Pauvrété
scatter u_NonGINI r_NonGINI
